package GUI;

import java.awt.Color;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import connector.Controler;

@SuppressWarnings("serial")
public class PlayersPane extends JPanel{
	private PokerTable players;
	private JLabel tableName;
	private JButton leaveButton;
	
	public PlayersPane(PokerTable players){
		this.players =  players;
		this.leaveButton = new JButton("Leave Table");
		this.leaveButton.setActionCommand(Controler.LEAVE_TABLE);
		this.leaveButton.addActionListener(players.getBoard());
		if(!players.isEmpty()){
			this.tableName = new JLabel(players.get(0).getName()+"\'s table");
		}else{
			this.tableName = new JLabel("Empty table");
		}
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.setBackground(Color.CYAN);
		this.paint();
	}
	public String getName(){
		return tableName.getText();
	}
	public int getPlayersNum(){
		return players.size();
	}
	public void updatePlayers(PokerTable players){
		this.players = players;
	}
	public void paint(){
		this.removeAll();
		tableName.setBorder(new EmptyBorder(10, 10, 10, 10));
		this.add(tableName);
		for(Player player:players){
			this.add(player);
		}
		this.add(leaveButton);
	}
}
